package com.company.OfferGuide;

import java.util.HashSet;
import java.util.Set;

public class 最长不含重复字符的子字符串 {

    public int lengthOfLongestSubstring(String s) {
        if (s.length() == 0) return 0;

        Set<Character> set = new HashSet<>();
        int max = 0;
        for (int l = 0, r = 0; r < s.length(); r++) {
            while (set.contains(s.charAt(r))) {
                set.remove(s.charAt(l++));
            }
            set.add(s.charAt(r));
            max = Math.max(max,r - l + 1);

        }

        return max;
    }

}
